<?php
	$dtype_id = 10;
	$result = mysql_query("SELECT title,remark FROM `tbl_discount_type` WHERE `dtype_id` = '$dtype_id'");
	$discount_title = mysql_result($result,0,0);
	$discount_remark = nl2br(mysql_result($result,0,1));
	
	$query = mysql_query("SELECT * FROM `tbl_discount_item` WHERE `dtype_id` = '$dtype_id' ORDER BY date_finish,date_start DESC");
	while($result = mysql_fetch_assoc($query)) {
		$brand = 'All';
		$product = 'All';
		$color = 'All';
		$size = 'All';
		$season = 'All';
		
		$temp = explode('{,}',$result['ditem_value']);
		$value_1 = $temp[0];
		$value_2 = $temp[1];
		
		$date_start = date('d-m-Y',$result['date_start']);
		$date_finish = date('d-m-Y',$result['date_finish']);
		$detail = $result['detail'];
		
		if($result['brand_id']!=0){
			$result2 = mysql_query("SELECT title FROM `tbl_brand` WHERE `brand_id` = '".$result['brand_id']."'");
			$brand = mysql_result($result2,0,0);
		}
		
		//if($result['product_id']!=0){
		//	$result2 = mysql_query("SELECT title FROM `tbl_brand` WHERE `brand_id` = '".$result['product_id']."'");
		//	$product = mysql_result($result2,0,0);
		//}
		//
		//if($result['color_id']!=0){
		//	$result2 = mysql_query("SELECT title FROM `tbl_brand` WHERE `brand_id` = '".$result['color_id']."'");
		//	$color = mysql_result($result2,0,0);
		//}
		//
		//if($result['size_id']!=0){
		//	$result2 = mysql_query("SELECT title FROM `tbl_brand` WHERE `brand_id` = '".$result['size_id']."'");
		//	$size = mysql_result($result2,0,0);
		//}
		//
		//if($result['season_id']!=0){
		//	$result2 = mysql_query("SELECT title FROM `tbl_brand` WHERE `brand_id` = '".$result['season_id']."'");
		//	$season = mysql_result($result2,0,0);
		//}
		
		$status	= $result['active'] ? 'active' : 'inactive';
		$content_id = $result['ditem_id'];
		$tp->apply();
	}
	
	mysql_free_result($query);
?>